package com.zn.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @Description
 * @Author zhaoning
 * @Date 2024/7/20
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RecordElement implements Comparable<RecordElement>{
    private Integer id;
    private LocalDateTime createAt;
    private Integer type; // 0 is customer to service, 1 is service to customer.

    private Integer to_id;
    private String message;

    @Override
    public int compareTo(RecordElement o) {
        return o.createAt.toString().compareTo(this.createAt.toString());
    }

    public static RecordElement toRE (UserRecord userRecord) {
        return new RecordElement(
                userRecord.getId(),
                userRecord.getCreateAt(),
                0,
                userRecord.getFromId(),
                userRecord.getMessage()
        );
    }

    public static RecordElement toRE (ServiceRecord serviceRecord) {
        return new RecordElement(
                serviceRecord.getId(),
                serviceRecord.getCreateAt(),
                1,
                serviceRecord.getToId(),
                serviceRecord.getMessage()
        );

    }
}
